/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jollylengkono.skripsi.Departments.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jollylengkono.skripsi.Departments.form.DepartmentsCreateForm;
import jollylengkono.skripsi.dao.DepartmentsDao;
import jollylengkono.skripsi.dao.MembersDao;
import jollylengkono.skripsi.model.Departments;
import jollylengkono.skripsi.model.Members;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author hp02
 */
public class DepartmentsCreate extends Action {
    private String FORWARD;
    private int STATE;

    public DepartmentsCreate() {
    }
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        DepartmentsCreateForm deptForm = (DepartmentsCreateForm) form;
        Departments department = new Departments();
        department.setDepartmentChief((Members) new MembersDao().read(deptForm.getId()));
        department.setDepartmentName(deptForm.getDepartmentName());
        this.STATE = new DepartmentsDao().create(department);
        if (this.STATE==1) {
            this.FORWARD="success";
        } else {
            this.FORWARD="fail";
        }
        return mapping.findForward(FORWARD);
    }
}
